package sort.insertionSort;

import helper.ArrayGenerator;
import helper.SortingHelper;
import model.Student;

public class InsertionSortTest {

    public static void main(String[] args) {
        Integer[] arr = {1, 4, 2, 3, 6, 5};
        InsertionSort.sort(arr);
        for (int i : arr) {
            System.out.print(i + " ");
        }

        System.out.println();

        Student[] students = {
                new Student("TT", 69),
                new Student("LY", 66),
                new Student("Alice", 96),
                new Student("Bobo", 11)};
        InsertionSort.sort(students);
        for (Student student : students) {
            System.out.print(student.toString() + " ");
        }

        System.out.println();

        int n = 10000;
        Integer[] randomArray = ArrayGenerator.generatorRandomArray(n, n);
        long startTime = System.nanoTime();
        InsertionSort.sort(randomArray);
        long endTime = System.nanoTime();
        double time = (endTime - startTime) / 1000000000.0;
        System.out.println("time:" + time + "s");
        boolean sorted = SortingHelper.isSorted(randomArray);
        System.out.println("randomArray是否正确排序：" + sorted);


        Integer[] randomArray2 = ArrayGenerator.generatorRandomArray(n, n);
        long startTime2 = System.nanoTime();
        InsertionSort.sort(randomArray2);
        long endTime2 = System.nanoTime();
        double time2 = (endTime2 - startTime2) / 1000000000.0;
        System.out.println("time2:" + time2 + "s");
        boolean sorted2 = SortingHelper.isSorted(randomArray2);
        System.out.println("randomArray2是否正确排序：" + sorted2);

    }

}
